package com.cinyi.ormlite.web.model;

import com.cinyi.ormlite.annotation.TSchema;
import com.cinyi.ormlite.core.BaseModel;
import com.cinyi.ormlite.core.IGenericDao;
import com.cinyi.ormlite.web.dao.JdbcGenericDaoImpl;
import com.cinyi.ormlite.web.dcp.DbConnectionManager;

@SuppressWarnings("rawtypes")
public class JdbcBaseModel<T extends BaseModel> extends BaseModel<T>{
	/**
	 * 数据库名
	 */
	private String schema = null ;
	/**
	 * 
	 */
	private IGenericDao<T> dao = null ;
	
	@Override
	public String getId() {
		return null;
	}

	public String getSchema()
    {
        if(schema == null ){
            schema = DbConnectionManager.DEFAULT_SCHEMA  ;
            if(this.getClass().isAnnotationPresent(TSchema.class)){
                TSchema schm = getClass().getAnnotation(TSchema.class);
                if(schm.alia() != null)
                    schema = schm.alia() ;
            }
        }
        return schema;
    }
    
	@Override
    public IGenericDao<T> getDao()
    {
        if(dao == null){
        	dao = new JdbcGenericDaoImpl<T>(getSchema());
        }
        return dao;
    }
	
}
